package com.lx.bbs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDto;
import com.lx.bbs.dao.ReplyMapper;
import com.lx.bbs.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.time.LocalDateTime;

/**
 * <p>
 * BBS论坛-回帖表-2 前端控制器
 * </p>
 *
 * @author lx
 * @since 2024-11-23
 */
@RestController
@RequestMapping("/reply")
public class ReplyController {

    @Autowired
    ReplyMapper replyMapper;

    @RequestMapping("queryByTid")
    public Page<Reply> queryByBid(int tid, int page, int rows) {
        Page<Reply> p = new PageDto<>(page, rows);
        return replyMapper.selectByTid(tid, p);
    }

    @RequestMapping("replyTopic")
    public Result replyTopic(String title, String content, int id, @SessionAttribute User myinfo){
        Reply reply = new Reply();
        reply.setTitle(title);
        reply.setContent(content);
        reply.setTopicid(id);
        reply.setUid(myinfo.getId());
        reply.setPublishtime(LocalDateTime.now());
        reply.setModifytime(LocalDateTime.now());
        replyMapper.insert(reply);
        return new Result(1, "回帖成功", null);
    }

}
